@Component
public class TaskExecutor {

    @Autowired
    private ThreadPoolExecutor executor;

    public void executeCountdownTask() {
        executor.execute(() -> {
            int countdown = 60;
            while (countdown >= 0) {
                System.out.println("倒计时: " + countdown + " 秒");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                countdown--;
            }
            System.out.println("倒计时结束！");
        });
    }

    public void executeTimeOutputTask() {
        executor.execute(() -> {
            while (true) {
                System.out.println("当前时间: " + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    break;
                }
            }
        });
    }
}
